package org.spring.demo.sdk;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;



public class WXPayConfig {
	
	
	public WXPayConfig() {
		setCertStream();
	}
	
	//App ID
	private String appId;
	//Mch ID
	private String mchid;
	//API 瀵嗛挜
	private String key;
	//绛惧悕璇佷功
	private InputStream certStream;
	//鑾峰彇WXPayDomain, 鐢ㄤ簬澶氬煙鍚嶅鐏捐嚜鍔ㄥ垏鎹�
	private IWXPayDomain iwxPayDomain;
	//璇佷功
	private byte[] certData;
	
	


    
	public String getAppId() {
		return appId;
	}

	public void setAppId(String appId) {
		this.appId = appId;
	}

	public String getMchid() {
		return mchid;
	}

	public void setMchid(String mchid) {
		this.mchid = mchid;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public InputStream getCertStream() {
		 ByteArrayInputStream certBis;
	     certBis = new ByteArrayInputStream(this.certData);
	     return certBis;
	}
	
	
	
	public void setCertStream() {
		
		File file = new File(WXPayConfig.class.getResource("/apiclient_cert.p12").getFile());
		InputStream certStream = null;
		try {
			certStream = new FileInputStream(file);
			this.certData = new byte[(int) file.length()];
	        certStream.read(this.certData);
		} catch (Exception e) {
			
		}finally{
			 try {
				certStream.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
        
       
	}

	public IWXPayDomain getIwxPayDomain() {
		return WXPayDomainSimpleImpl.instance();
	}

	

	
	/**
     * HTTP(S) 杩炴帴瓒呮椂鏃堕棿锛屽崟浣嶆绉�
     *
     * @return
     */
    public int getHttpConnectTimeoutMs() {
        return 6*1000;
    }

    /**
     * HTTP(S) 璇绘暟鎹秴鏃舵椂闂达紝鍗曚綅姣
     *
     * @return
     */
    public int getHttpReadTimeoutMs() {
        return 8*1000;
    }

    

    /**
     * 鏄惁鑷姩涓婃姤銆�
     * 鑻ヨ鍏抽棴鑷姩涓婃姤锛屽瓙绫讳腑瀹炵幇璇ュ嚱鏁拌繑鍥� false 鍗冲彲銆�
     *
     * @return
     */
    public boolean shouldAutoReport() {
        return true;
    }

    /**
     * 杩涜鍋ュ悍涓婃姤鐨勭嚎绋嬬殑鏁伴噺
     *
     * @return
     */
    public int getReportWorkerNum() {
        return 6;
    }


    /**
     * 鍋ュ悍涓婃姤缂撳瓨娑堟伅鐨勬渶澶ф暟閲忋�備細鏈夌嚎绋嬪幓鐙珛涓婃姤
     * 绮楃暐璁＄畻锛氬姞鍏ヤ竴鏉℃秷鎭�200B锛�10000娑堟伅鍗犵敤绌洪棿 2000 KB锛岀害涓�2MB锛屽彲浠ユ帴鍙�
     *
     * @return
     */
    public int getReportQueueMaxSize() {
        return 10000;
    }

    /**
     * 鎵归噺涓婃姤锛屼竴娆℃渶澶氫笂鎶ュ涓暟鎹�
     *
     * @return
     */
    public int getReportBatchSize() {
        return 10;
    }

}
